package open.tech.dawn.rest.common.jdbc;

import java.util.Date;

import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;

@Component
public class RestMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        if (metaObject.hasSetter("createtime")) {
            this.strictInsertFill(metaObject, "createtime", Date.class, new Date());
        }
        if (metaObject.hasSetter("updatetime")) {
            this.strictInsertFill(metaObject, "updatetime", Date.class, new Date());
        }
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        if(metaObject.hasSetter("updatetime")) {
            this.strictUpdateFill(metaObject, "updatetime", Date.class, new Date());
        }
    }

}
